var express = require('express')
var router = express.Router()

router.get('/', (req, res) => {
  res.redirect('/zh-cn/index.html')
})

router.get('/login', (req, res, next) => {
  res.render('login', { title: '登录' })
})

router.post('/login', (req, res, next) => {
  if (req.body.username === 'admin' && req.body.password === '1234') {
    req.session.username = req.body.username
    console.log(req.session.cookie)
    res.redirect('/')
  } else {
    res.send('用户名或密码错误')
  }
})

router.get('/api/test', (req, res, next) => {
  if (req.session.username) {
    res.send('OK')
  } else {
    res.send('NO')
  }
})

module.exports = router
